<template>
  <div>
    <!--搜索表单-->
    <div style="margin-bottom: 20px">
      <el-input style="width: 240px" placeholder="请输入" v-model="params.roomid"></el-input>
      <el-button style="margin-left: 5px" type="primary" @click="load"><i class="el-icon-search"></i>搜索</el-button>
    </div>
    <!--    数据表单-->
    <el-table :data="tableData" stripe>
      <el-table-column prop="roomid" label="教室号"></el-table-column>
      <el-table-column prop="state" label="教室状态"></el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <!--        当前行数据-->
          <el-button type="primary" @click="$router.push('/serviceRoom?roomid=' + scope.row.roomid)">借用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div>
      <el-pagination
          background
          :current-page="params.pageNum"
          :page-size="params.pageSize"
          layout="prev, pager, next"
          @current-change="handelCurrentChange"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: 'Borrow.vue',
  data() {
    return {
      tableData: [],
      total: 0,
      params: {
        pageNum: 1,
        pageSize: 10,
        roomid: '',
        state: '空闲'
      }
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      // fetch('http://localhost:9090/room/list').then(res => res.json()).then(res => {
      //   console.log(res)
      //   this.tableData = res
      // })

      request.get('/room/page', {
        params: this.params
      }).then(res => {
        this.tableData = res.data.list
        this.total = res.data.total
        if (res.code === '200') {
          this.tableData = res.data.list
          this.total = res.data.total
        }

      })

    },
    handelCurrentChange(pageNum) {
      this.params.pageNum = pageNum
      this.load()
    }
  }
}
</script>

<style scoped>

</style>